<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <title>专家问答</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f9f9f9;
        }

        h2 {
            text-align: center;
            color: #333;
        }

        .ask-question {
            display: inline-block;
            margin-bottom: 20px;
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            font-weight: bold;
        }

        .ask-question:hover {
            background-color: #45a049;
        }

        .question-container {
            margin-bottom: 30px;
            padding: 20px;
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 6px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        }

        .question-title {
            margin-top: 0;
            color: #333;
        }

        .question-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
            font-size: 14px;
            color: #666;
        }

        .answer {
            margin-top: 15px;
            padding: 15px;
            background-color: #eef6eb;
            border-left: 4px solid #4CAF50;
        }

        .answer h4 {
            margin-top: 0;
            color: #2e7d32;
        }

        .answer-content {
            margin-bottom: 10px;
            line-height: 1.6;
        }

        .answer-meta {
            font-size: 12px;
            color: #555;
        }

        form {
            margin-top: 15px;
        }

        label {
            display: block;
            margin-bottom: 6px;
            font-weight: bold;
            color: #333;
        }

        textarea {
            width: 100%;
            height: 120px;
            padding: 10px;
            font-size: 14px;
            border: 1px solid #ccc;
            border-radius: 4px;
            resize: vertical;
            box-sizing: border-box;
        }

        button {
            margin-top: 10px;
            padding: 10px 20px;
            background-color: #2196F3;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
        }

        button:hover {
            background-color: #1976D2;
        }

        .container {
            max-width: 800px;
            margin: auto;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>专家问答</h2>
    <a href="${pageContext.request.contextPath}/expert/ask" class="ask-question">提问</a>

    <c:forEach var="question" items="${questions}">
        <div class="question-container">
            <h3 class="question-title">${question.title}</h3>
            <div class="question-header">
                <span>提问者：${question.userId} | 分类：${question.categoryId}</span>
                <span>提问时间：<fmt:formatDate value="${question.createTime}" pattern="yyyy-MM-dd HH:mm"/></span>
            </div>
            <p>${question.content}</p>

            <!-- 回答展示 -->
            <c:set var="answer" value="${answerService.getAnswerByQuestionId(question.id)}"/>
            <c:if test="${not empty answer}">
                <div class="answer">
                    <h4>专家回答：</h4>
                    <div class="answer-content">${answer.answer}</div>
                    <div class="answer-meta">
                        回答时间：<fmt:formatDate value="${answer.answerTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                    </div>
                </div>
            </c:if>

            <!-- 回答表单 -->
            <form action="${pageContext.request.contextPath}/expert/reply/${question.id}" method="post">
                <label for="answerContent">请输入回答：</label>
                <textarea id="answerContent" name="answerContent" placeholder="在此输入您的回答..." required></textarea>
                <button type="submit">提交回答</button>
            </form>
        </div>
    </c:forEach>
</div>
</body>
</html>
